﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace MixScript.BLL.FI
{
    public class cPeriod : cBaseBLL
    {

        private cPeriod() { }


        public void listMasterByAktif(out DataTable dt, Int32 aktif)
        {
            string sSQL = @"select id,periode_id, CAST(awal AS NVARCHAR(12)) as awal,CAST(akhir AS NVARCHAR(12)) akhir from accperiod where aktif={0}";
            dt = Dbserver.ExecuteQuery(string.Format(sSQL, aktif), "TMasterPeriod");
        }
        public void listMasterByID(out DataTable dt, Int32 ID)
        {
            string sSQL = @"select id,periode_id, CAST(awal AS NVARCHAR(12)) as awal,CAST(akhir AS NVARCHAR(12)) akhir from accperiod where ID={0}";
            dt = Dbserver.ExecuteQuery(string.Format(sSQL, ID), "TMasterPeriod");
        }

        public void listPeriodByID(out DataTable dt, Int32 ID)
        {
            string sSQL = @"select id,CAST(periode AS NVARCHAR(12)) as periode,
                        CAST(lastdate AS NVARCHAR(12)) as lastdate,closing,period_id  
                        from accmonthly WHERE period_id = {0} ORDER BY periode";
            dt = Dbserver.ExecuteQuery(string.Format(sSQL, ID), "Tperiod");
        }
        public bool InsertMonthly(string period, string lastDate, Int32 PeriodID)
        {
            Dbserver.openConn();
            string sSQL = @"INSERT INTO accmonthly (periode,lastdate, period_id) VALUES ('{0}','{1}','{2}')";
            Dbserver.ExecuteNonQuery(String.Format(sSQL, period, lastDate, PeriodID));
            Dbserver.CommitAndCloseConn();
            return true;
        }
        public bool DeleteMaster(Int32 id)
        {
            Dbserver.openConn();
            string sSQL = @"delete accperiod where ID = {0})";
            Dbserver.ExecuteNonQuery(String.Format(sSQL, id));

            string sSQL1 = @"delete accmonthly where Period_ID = {0})";
            Dbserver.ExecuteNonQuery(String.Format(sSQL1, id));
            Dbserver.CommitAndCloseConn();
            return true;
        }
        public bool DeleteMonthly(Int32 id)
        {
            Dbserver.openConn();
            string sSQL = @"delete accmonthly where ID = {0})";
            Dbserver.ExecuteNonQuery(String.Format(sSQL, id));
            Dbserver.CommitAndCloseConn();
            return true;
        }


    }
}
